home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fsutil / fsutilSync.c < prev    next >
C/C++ Source or Header  |  1991-04-29  |  5KB  |  200 lines

  1. /* 
  2.  * fsutilSync.c --
  3.  *
  4.  * Routines controlling the syncing of cached data to disk or the server.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/fsutil/RCS/fsutilSync.c,v 9.2 91/01/26 15:35:47 mgbaker Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <sprite.h>
  22.  
  23. #include <fs.h>
  24. #include <vm.h>
  25. #include <rpc.h>
  26. #include <fsutil.h>
  27. #include <fsdm.h>
  28. #include <fslcl.h>
  29. #include <fsNameOps.h>
  30. #include <fsprefix.h>
  31. #include <fsStat.h>
  32. #include <sync.h>
  33. #include <timer.h>
  34. #include <proc.h>
  35. #include <trace.h>
  36. #include <hash.h>
  37. #include <fsrmt.h>
  38.  
  39. #include <stdio.h>
  40.  
  41. #define    MAX_WAIT_INTERVALS    5
  42.  
  43.  
  44. Boolean fsutil_ShouldSyncDisks;
  45.  
  46. int        fsWriteBackInterval = 30;    /* How long blocks have to be
  47.                          * dirty before they are
  48.                          * written back. */
  49. int        fsWriteBackCheckInterval = 5;    /* How often to scan the
  50.                          * cache for blocks to write
  51.                          * back. */
  52. Boolean        fsutil_ShouldSyncDisks = TRUE;    /* TRUE means that we should
  53.                          * sync the disks when
  54.                          * Fsutil_SyncProc is called. */
  55. int        lastHandleWBTime = 0;        /* Last time that wrote back
  56.                          * file handles. */
  57. /*
  58.  *----------------------------------------------------------------------
  59.  *
  60.  * Fsutil_SyncProc --
  61.  *
  62.  *    Process to loop and write back things every thiry seconds.
  63.  *
  64.  * Results:
  65.  *    None.
  66.  *
  67.  * Side effects:
  68.  *    None.
  69.  *
  70.  *----------------------------------------------------------------------
  71.  */
  72. /*ARGSUSED*/
  73. void
  74. Fsutil_SyncProc(data, callInfoPtr)
  75.     ClientData        data;        /* IGNORED */
  76.     Proc_CallInfo    *callInfoPtr;
  77. {
  78.     int    blocksLeft;
  79.  
  80.     if (Fsutil_TimeInSeconds() - lastHandleWBTime >= fsWriteBackInterval) {
  81.     (void) Fsutil_HandleDescWriteBack(FALSE, -1);
  82.     lastHandleWBTime = Fsutil_TimeInSeconds();
  83.     }
  84.  
  85.     if (fsutil_ShouldSyncDisks) {
  86.     Fscache_WriteBack((unsigned) (Fsutil_TimeInSeconds() -
  87.         fsWriteBackInterval), &blocksLeft, FALSE);
  88.     }
  89.     if (fsWriteBackCheckInterval < fsWriteBackInterval) {
  90.     callInfoPtr->interval = fsWriteBackCheckInterval * timer_IntOneSecond;
  91.     } else {
  92.     callInfoPtr->interval = fsWriteBackInterval * timer_IntOneSecond;
  93.     }
  94.  
  95. }
  96.  
  97.  
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * Fsutil_Sync --
  102.  *
  103.  *    Write back bit maps, file descriptors, and all dirty cache buffers.
  104.  *
  105.  * Results:
  106.  *    None.
  107.  *
  108.  * Side effects:
  109.  *    None.
  110.  *
  111.  *----------------------------------------------------------------------
  112.  */
  113.  
  114. void
  115. Fsutil_Sync(writeBackTime, shutdown)
  116.     unsigned int writeBackTime;    /* Write back all blocks in the cache and file
  117.                        descriptors that were dirtied before 
  118.                    this time. */
  119.     Boolean    shutdown;    /* TRUE if the kernel is being shutdown. */
  120. {
  121.     int        blocksLeft = 0;
  122.     /*
  123.      * Force all file descriptors into the cache.
  124.      */
  125.     (void) Fsutil_HandleDescWriteBack(shutdown, -1);
  126.     /*
  127.      * Write back the cache.
  128.      */
  129.     Fscache_WriteBack(writeBackTime, &blocksLeft, shutdown);
  130.     if (shutdown) {
  131.     if (blocksLeft) {
  132.         printf("Fsutil_Sync: %d blocks still locked\n", blocksLeft);
  133.     }
  134. #ifdef notdef
  135.     Fscache_CleanBlocks((ClientData) FALSE, (Proc_CallInfo *) NIL);
  136. #endif
  137.     }
  138.     /*
  139.      * Finally write all domain information to disk.  This will mark each
  140.      * domain to indicate that we went down gracefully and recovery is in
  141.      * fact possible.
  142.      */
  143.     Fsdm_DomainWriteBack(-1, shutdown, FALSE);
  144. }
  145.  
  146. /*
  147.  *----------------------------------------------------------------------
  148.  *
  149.  * Fsutil_SyncStub --
  150.  *
  151.  *    Procedure bound to the L1-w keystoke.  This is called at
  152.  *    keyboard interrupt time and so it makes a Proc_CallFunc
  153.  *    to invoke the Fsutil_Sync procedure.
  154.  *
  155.  * Results:
  156.  *    None.
  157.  *
  158.  * Side effects:
  159.  *    Attempts to sync the disks.
  160.  *
  161.  *----------------------------------------------------------------------
  162.  */
  163. void SyncCallBack();
  164.  
  165. void
  166. Fsutil_SyncStub(data)
  167.     ClientData        data;
  168. {
  169.     printf("Queueing call to Fsutil_Sync() ... ");
  170.     Proc_CallFunc(SyncCallBack, data, 0);
  171. }
  172.  
  173.  
  174. /*
  175.  *----------------------------------------------------------------------
  176.  *
  177.  * Fs_SyncCallBack --
  178.  *
  179.  *    Procedure called via Proc_CallFunc to sync the disks.
  180.  *
  181.  * Results:
  182.  *    None.
  183.  *
  184.  * Side effects:
  185.  *    Syncs the disk.
  186.  *
  187.  *----------------------------------------------------------------------
  188.  */
  189. void
  190. SyncCallBack(data, callInfoPtr)
  191.     ClientData        data;
  192.     Proc_CallInfo    *callInfoPtr;
  193. {
  194.     printf("Syncing disks");
  195.     Fsutil_Sync(-1, (Boolean)data);
  196.     callInfoPtr->interval = 0;
  197.     printf(".\n");
  198. }
  199.  
  200.